package parkingManage.model;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;

/**
 * 收费记录
 * 
 * @author 伟❤志
 *
 */
public class RecordModel {

	private Integer id;// 记录编号
	private String carLicense;// 车牌号
	private int lotCode;// 停车位号
	private LocalDateTime startTime;// 进入时间
	private LocalDateTime leaveTime;// 离开时间
	private BigDecimal free = new BigDecimal(0);// 费用

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getCarLicense() {
		return carLicense;
	}

	public void setCarLicense(String carLicense) {
		this.carLicense = carLicense;
	}

	public int getLotCode() {
		return lotCode;
	}

	public void setLotCode(int lotCode) {
		this.lotCode = lotCode;
	}

	public LocalDateTime getStartTime() {
		return startTime;
	}

	public void setStartTime() {
		this.startTime = LocalDateTime.now();
	}

	public LocalDateTime getLeaveTime() {
		return leaveTime;
	}

	public void setLeaveTime() {
		this.leaveTime = LocalDateTime.now();
	}

	public void setFree(BigDecimal free) {
		this.free = free;
	}

	public BigDecimal getFree() {
		return free;
	}

	// 计算费用
	public void setFree() {

		BigDecimal t1 = new BigDecimal(ChronoUnit.MINUTES.between(this.startTime, this.leaveTime));
		BigDecimal hours = t1.divide(new BigDecimal("60"), RoundingMode.CEILING);
		this.free = hours.multiply(new BigDecimal("2"));
	}

	public RecordModel(int id, String carLicense, int lotCode, LocalDateTime staTime, LocalDateTime leaTime,
			BigDecimal free) {
		this.carLicense = carLicense;
		this.free = free;
		this.leaveTime = leaTime;
		this.startTime = staTime;
		this.lotCode = lotCode;
		this.id = id;
	}

	public RecordModel() {
	}
}
